<!--上传文件-->
<link rel="stylesheet" href="__STATIC__/admin/css/edit_common.css">

<link rel="stylesheet"type="text/css"href="__STATIC__/admin/uploadify/uploadify.css" />
<script type="text/javascript" src="http://api.map.baidu.com/api?v=2.0&ak=PBw9wnafmrxp5loOGMd0ht59"></script>


<style>
    #commodity_main input[type=text]{width: 98%;}
    #commodity_main input[type=file]{margin-bottom: 10px;}
    #commodity_main img{width: 120px;height: 120px;border-radius: 50%;background-color: #FFFFFF;border-color:#FFFFFF;}
    #l-map{border: 1px solid #ddd;}
    #l-map {height: 300px;width: 100%;}
</style>

<div id="commodity_details">
    <h1 style="margin-top: 0px!important;">
        <img src="__STATIC__/admin/img/ico.png">
        联系我们
        <a href="javascript:history.go(-1);"><span><img src="__STATIC__/admin/img/return.png"></span></a>
    </h1>
    </h1>
</div>

<div class="page-content">
    <div class="row">
        <div class="col-xs-12">
            <!-- PAGE CONTENT BEGINS -->
            <form class="form-horizontal" role="form" method="post" url="{:url()}" id="login_form">

                <div class="form-group">
                    <label class="col-sm-1 control-label no-padding-right"> 文本 </label>
                    <div class="col-sm-11">
                        <textarea name="info" id="info_text" cols="30" rows="10">{$linkConfig['LINK_INFO']}</textarea>
                    </div>
                </div>

                <div class="form-group">
                    <label class="col-sm-1 control-label no-padding-right"> 位置 </label>
                    <div class="col-sm-11">
                        <!-- 默认地址文本不显示 -->
                        <input type="text" name="address" value="" id="suggestId" >
                        <span style="color: red;">请在下面地图中选择店铺地址</span>
                        <div id="searchResultPanel" style="border:1px solid #C0C0C0;width:150px;height:auto; display:none;"></div>
                        <div id="l-map"></div>
                    </div>
                </div>

                <div class="clearfix form-actions">
                    <div class="col-md-offset-3 col-md-9">
                        <button class="btn btn-info" type="button" id="saveBtn">
                            <i class="icon-ok bigger-110"></i>
                            保存
                        </button>
                    </div>
                </div>
            </form>
        </div><!-- /.col -->
    </div><!-- /.row -->
</div><!-- /.page-content -->

{load href="__STATIC__/admin/js/image.js" /}
<script>
    $(".pp").addClass("active open");
    $(".pp .lxwm").addClass("active");
</script>
<!-- 配置文件 -->
<script type="text/javascript" src="__STATIC__/ueditor/ueditor.config.js"></script>
<!-- 编辑器源码文件 -->
<script type="text/javascript" src="__STATIC__/ueditor/ueditor.all.js"></script>
<!--编辑器语言加载-->
<script type="text/javascript" src="__STATIC__/ueditor/lang/zh-cn/zh-cn.js"></script>

<link type="text/css" rel="stylesheet" href="__STATIC__/ueditor/third-party/video-js/video-js.css"/>
<script language="javascript" type="text/javascript" src="__STATIC__/ueditor/third-party/video-js/video.js"></script>

<!-- 实例化编辑器 -->
<script type="text/javascript">
    let config = {
        initialFrameWidth: "100%", //初化宽度
        initialFrameHeight: 200, //初化高度
        serverUrl: "{$server_url}",
        maximumWords: 99999, removeFormatAttributes: 'class,style,lang,width,height,align,hspace,valign',//允许的最大字符数 'fullscreen',
        toolbars: [
            ['fullscreen', 'source', '|', 'undo', 'redo','|', 'bold', 'italic', 'underline', 'fontborder',
                'strikethrough', 'removeformat', 'formatmatch', 'autotypeset',
                'blockquote', 'pasteplain', '|', 'forecolor','backcolor', 'insertorderedlist',
                'insertunorderedlist', 'selectall', 'cleardoc', '|','rowspacingtop', 'rowspacingbottom',
                'lineheight', '|','customstyle', 'paragraph', 'fontfamily', 'fontsize','|','indent' , 'justifyleft', 'justifycenter','justifyright',
                'justifyjustify',  '|', 'link', 'unlink', 'horizontal']
        ]
    };
    let ue = UE.getEditor('info_text',config);
</script>
<!-- 百度地图相关script -->
<script type="text/javascript">
    var lat = "{$linkConfig['LOCATION_LAT']}";
    var lng = "{$linkConfig['LOCATION_LNG']}";
    // 百度地图API功能
    function G(id) {
        return document.getElementById(id);
    }
    var map = new BMap.Map("l-map");
    map.centerAndZoom('广东省广州市' , 11);                   // 初始化地图,设置城市和地图级别。

    //默认加载地址
    var point = new BMap.Point(lng, lat);
    var marker = new BMap.Marker(point);  // 创建标注
    map.addOverlay(marker);               // 将标注添加到地图中
    marker.setAnimation(BMAP_ANIMATION_BOUNCE); //跳动的动画

    map.enableScrollWheelZoom();   //启用滚轮放大缩小，默认禁用
    map.enableContinuousZoom();    //启用地图惯性拖拽，默认禁用

    map.addEventListener("click", function (e) {
        lat = e.point.lat;
        lng = e.point.lng;
        map.clearOverlays();    //清除地图上所有覆盖物
        var point = new BMap.Point(e.point.lng, e.point.lat);
        var marker = new BMap.Marker(point);  // 创建标注
        map.addOverlay(marker);               // 将标注添加到地图中
        marker.setAnimation(BMAP_ANIMATION_BOUNCE); //跳动的动画
    });

    var ac = new BMap.Autocomplete(    //建立一个自动完成的对象
        {
            "input": "suggestId"
            , "location": map
        });

    ac.addEventListener("onhighlight", function (e) {  //鼠标放在下拉列表上的事件
        var str = "";
        var _value = e.fromitem.value;
        var value = "";
        if (e.fromitem.index > -1) {
            value = _value.province + _value.city + _value.district + _value.street + _value.business;
        }
        str = "FromItem<br />index = " + e.fromitem.index + "<br />value = " + value;

        value = "";
        if (e.toitem.index > -1) {
            _value = e.toitem.value;
            value = _value.province + _value.city + _value.district + _value.street + _value.business;
        }
        str += "<br />ToItem<br />index = " + e.toitem.index + "<br />value = " + value;
        G("searchResultPanel").innerHTML = str;
    });

    var myValue;
    ac.addEventListener("onconfirm", function (e) {    //鼠标点击下拉列表后的事件
        var _value = e.item.value;
        myValue = _value.province + _value.city + _value.district + _value.street + _value.business;
        G("searchResultPanel").innerHTML = "onconfirm<br />index = " + e.item.index + "<br />myValue = " + myValue;

        setPlace();
    });

    function setPlace() {
        map.clearOverlays();    //清除地图上所有覆盖物
        function myFun() {
            var pp = local.getResults().getPoi(0).point;    //获取第一个智能搜索的结果
            map.centerAndZoom(pp, 18);
            map.addOverlay(new BMap.Marker(pp));    //添加标注
            lat = pp.lat;
            lng = pp.lng;
        }

        var local = new BMap.LocalSearch(map, { //智能搜索
            onSearchComplete: myFun
        });
        local.search(myValue);
    }

    //删除渠道
    $('#saveBtn').on('click', function(){
        $.ajax({
            type: 'POST',
            url: "{:url('')}",
            data: {
                'lat': lat,
                'lng': lng,
                'info': ue.getContent(),
            },
            dataType: "json",
            success: function(data) {
                var result = eval(data);
                alert(result.message);
                if (result.status == 0) {
                    location.reload();
                }
            }
        });
    });
</script>